<template>
	<view class="login">
		<view class="container">
			<!--顶部返回按钮-->
			<!-- <text class="back-btn iconfont iconzuo" @tap="navBack"></text> -->
			<!--插画-->
			<view class="right-top-sign">
				<image style="width: 100%; height: 14vh;"
					src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/3410683c2e1a9e1cffd86375da3fd8c1fd0f232c.png"
					mode="scaleToFill" />
			</view>

			<view class="wrapper">
				<view class="left-top-sign">
					<image class="img_s"
						src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/13f03ffe422bbc55aa7d2d2f1c29db1e0d3ea77f.png"
						mode="scaleToFill" />
				</view>
				<!-- <view class="welcome">
					欢迎回来！
				</view> -->
				<view class="input-content">
					<view class="input-item">
						<input type="number"  placeholder="请输入手机号" maxlength="11" v-model="mobiles" :clearabled="true"/>
					</view>
					<view class="input-item">
						<input  type="password" placeholder="请输入密码" maxlength="20" v-model="passwords" />
					</view>
				</view>
				<view class="section-5 flex-align">
					<label for="">
						<u-checkbox-group v-model="checked" placement="row" @change="checkboxChange" iconSize='20px'
							size='20px'>
							<u-checkbox label="我已阅读并认可" activeColor="rgb(255, 101, 85)" labelSize="13px"
								labelColor="#999999" :checked="false">
								<!-- checked="true" -->
								<!-- 18210979796 -->
							</u-checkbox>
						</u-checkbox-group>

					</label>

					<view class="info-1 flex-align">
						<!-- <text>我已阅读并同意</text> -->
						<view class="info-2" @click="showInfo = true" style="font-size: 26rpx;">《免责说明协议》</view>
					</view>
				</view>
				<!-- <button class="confirm-btn" shape="circle" @click="denglu()">
					登录
				</button> -->
				<view class="btn_s" @click="denglu">
					登录
				</view>
			</view>
			<view class="register-section">
				<text @tap="toHome">申请入驻</text>
			</view>
			<view class="right-top-signw">
				<image style="width: 100%; height: 19vh;"
					src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/274f070341df6caaab84cc853c133edfaf49adfb.png"
					mode="scaleToFill" />
			</view>
		</view>
		<u-popup @touchmove.stop :show="showInfo" @close="closeInfo" closeOnClickOverlay mode="bottom" round="15">
			<view class="store-popup">
				<view class="title flex-between">
					<text>免责说明协议</text>
					<u-icon @click="closeInfo" name="close-circle-fill" color="#dde3e8" size="18"></u-icon>
				</view>
				<!-- <view class="list-2" style="width: 100%; max-height: 60vh; padding: 0 20rpx 0 20rpx">
					<u-parse :content="ticketData.content"></u-parse>
				</view> -->
			</view>
		</u-popup>
		<view class="popup_s" v-if="popup_s" @click="popup_list"></view>
		<view class="popup_info" v-if="popup_s">
			<view style="width: 100%;height: 80rpx;position: relative;top: 0;left: 0;">
				<view style="position: absolute;top: 10rpx;left: 0;color: #fa4c4c;">
					选择项目
				</view>
				<view style="position: absolute;top: 0;right: 0;font-size: 42rpx;color: #fa4c4c;" @click="popup_clo">
					×
				</view>
			</view>
			<scroll-view scroll-y class="popup_info_ten">
				<!-- <view v-for="(item,index) in user" :key="index" class="popup_name" @click="popup_name(item)">
					{{item.entry_name}}
				</view> -->
				<view v-for="(item,index) in user" :key="index" class="popup_name" @click="popup_name(item)">
					{{item.entry_name}}
					<!-- <text>当前</text> -->
				</view>
			</scroll-view class="table" scroll-y style="height: 1100rpx;;">

		</view>
	</view>
</template>
<script>
	const index = require("@/api/index/index.js");
	export default {

		data() {
			return {
				mobiles: '',
				passwords: '',
				project_id: '',
				showInfo: false,
				popup_s: false,
				user: [],
				project_id: '',
				checked: false,
				read_checked: false,
			};
		},
		onLoad() {
		},
		onShow() {
			// 检查本地存储中是否存在历史账号和密码
			// const phoneNumber = uni.getStorageSync('phoneNumber');
			// const passwords = uni.getStorageSync('passwords');
			// if (phoneNumber && passwords) {
			// 	// 将历史账号和密码自动填充到登录页面的输入框中
			// 	this.mobiles = phoneNumber;
			// 	this.passwords = passwords;
			// }
		},
		mounted() {
			// 检查本地存储中是否存在历史账号和密码
			const phoneNumber = uni.getStorageSync('phoneNumber');
			const passwords = uni.getStorageSync('passwords');

			if (phoneNumber && passwords) {
				// 将历史账号和密码自动填充到登录页面的输入框中
				this.mobiles = phoneNumber;
				this.passwords = passwords;
			}
		},
		methods: {
			// 免责说明协议
			checkboxChange(e) {
				if (e.length == 0) {
					this.read_checked = false;
				} else {
					this.read_checked = true;
				}
			},
			closeInfo() {
				this.showInfo = false;
			},
			// 登录
			async projects() {
				let that = this;
				let data = {
					mobile: this.mobiles,
				};
				let result = await index.projects(data);
				if (result.code == 1) {
					if (result.data.multiple == 1) {
						// that.popup_s = true
						that.user = result.data.user
					} else if (result.data.multiple == 0) {
						that.project_id = result.data.user[0].project_id
					}
				}
			},
			popup_list() {
				this.popup_s = false
			},
			popup_name(item) {
				this.project_id = item.project_id
				this.popup_s = false
				this.denglu()

			},
			async denglu() {
				let that = this;
				if (this.read_checked == false) {
					return uni.showToast({
						title: "请先阅读购买须知",
						icon: "none",
					});
				}
				let data = {
					mobile: this.mobiles,
					password: this.passwords,
					project_id: this.project_id
				};
				let result = await index.login(data);
				if (result.code == 1) {
					if (result.data.multiple == 1) {
						that.popup_s = true
						that.user = result.data.projectList
						uni.setStorageSync('phoneNumber', that.mobiles);
						uni.setStorageSync('passwords', that.passwords);
					} else {
						uni.setStorageSync('token', result.data.token);
						console.log(uni.getStorageSync("token"),'uni.getStorageSync("token")123')
						let items = JSON.stringify(result.data.venues);
						uni.setStorageSync("wqzdy", items);
						uni.setStorageSync('entry_name', result.data.user.entry_name);
						uni.setStorageSync('project_id', result.data.user.project_id);
						uni.setStorageSync('user_name', result.data.user.user_name);
						uni.setStorageSync('describe', result.data.user.describe);
						uni.setStorageSync('nickname', result.data.user.nickname);
						uni.setStorageSync('headimg', result.data.user.head_img);
						uni.setStorageSync('menus', result.data.menus);
						uni.setStorageSync('mobiles', that.mobiles);
						uni.setStorageSync('phoneNumber', that.mobiles);
						uni.setStorageSync('passwords', that.passwords);
						uni.reLaunch({
							url: '/pages/my-center/my-center'
						})
					}
					// uni.reLaunch({
					// 	url: '/pages/my-center/my-center'
					// })
				} else {
					// uni.showToast({
					// 	title: result.info,
					// 	icon: 'none',
					// 	duration: 2000
					// })
					this.project_id = ''
					uni.showModal({
						title: '提示',
						content: result.info,
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					that.popup_s = false
				}
			},
			toHome() {
				uni.navigateTo({
					url: '/page_venues/residence/residence'
				})
			}

		}
	}
</script>
<style lang="scss">
	.container {
		position: relative;
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background: #fff;

		.wrapper {
			position: relative;
			z-index: 90;
			margin-top: 45%;

			.section-5 {
				margin-left:20vw;
				margin-top: 6vh;

				.info-1 {
					font-size: 32rpx;
					font-weight: 500;
					color: #999999;
				}

				.info-2 {
					color: rgb(255, 101, 85);
				}
			}

			.confirm-btn {
				width: 90%;
				height: 80rpx;
				line-height: 80rpx;
				background-color: rgb(255, 101, 85);
				border-radius: 40rpx;
				text-align: center;
				color: #fff;
				float: inherit;
				margin: 20rpx 38rpx 25rpx 38rpx;

			}

			.btn_s {
				width: 90%;
				height: 80rpx;
				line-height: 80rpx;
				background-color: rgb(255, 101, 85);
				border-radius: 40rpx;
				text-align: center;
				color: #fff;
				margin: 20rpx 38rpx 25rpx 38rpx;
			}

			.btn_s:hover {
				background-color: rgb(255, 85, 0);
			}
		}

		.back-btn {
			position: absolute;
			left: 40rpx;
			z-index: 9999;
			top: 40rpx;
			font-size: 40rpx;
		}

		.left-top-sign {
			width: 100%;
			height: 250rpx;
			text-align: center;

			.img_s {
				vertical-align: middle;
				width: 25vw;
				height: 23vw;
			}
		}

		.right-top-sign {
			width: 100%;
			height: 20vh;
			position: absolute;
			top: 0;
			z-index: 999;
		}

		.right-top-signw {
			position: absolute;
			width: 100%;
			height: 20vh;
			bottom: 0;
			z-index: 999;

		}

		.left-bottom-sign {
			position: absolute;
			left: -270rpx;
			bottom: -320rpx;
			border: 100rpx solid #d0d1fd;
			border-radius: 50%;
			padding: 180rpx;
		}

		.welcome {
			position: relative;
			left: 50rpx;
			top: -90rpx;
			font-size: 46rpx;
			color: #555;
			text-shadow: 1px 0px 1px rgba(0, 0, 0, 0.3);
		}

		.input-content {
			padding: 0 60rpx;

		}

		.input-item {
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: center;
			padding: 0 30rpx;
			height: 100rpx;
			border-radius: 4px;
			margin-bottom: 20rpx;
			background-color: #F0F3F7;
			border-radius: 60rpx 60rpx;

			&:last-child {
				margin-bottom: 0;
			}

			.tit {
				height: 50rpx;
				line-height: 56rpx;
			}

			input {
				height: 60rpx;
				width: 90%;
				margin-left: 30rpx;
				font-size: 30rpx;
			}
		}

		.input-item-sms-code {
			position: relative;
			width: 100%;

			.sms-code-btn {
				position: absolute;
				color: #111;
				right: 20rpx;
				bottom: 20rpx;
				font-size: 28rpx;
			}

			.sms-code-resend {
				color: #999;
			}

			.sms-code-btn:after {
				border: none;
				background-color: transparent;
			}
		}

		.forget-section {
			text-align: center;
			margin-top: 40rpx;
		}

		.register-section {
			margin: 20rpx 0 50rpx 0;
			width: 100%;
			text-align: center;

			text {
				margin-left: 10rpx;
				font-size: 26rpx;
				color: #999;
			}

			text:first-child {
				margin-right: 10rpx;
			}
		}

		.btn-group {
			display: flex;
			margin-bottom: 20rpx;
		}
	}

	.popup_s {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		width: 100vw;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.8);
		z-index: 9998;
	}

	.popup_info {
		position: fixed;
		width: 530rpx;
		height: 743rpx;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		font-size: 30rpx;
		padding: 40rpx;
		overflow: hidden;
		background-image: url('https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/e89844bfef73c699ef06622d923147613e4585af.png');
		background-repeat: no-repeat;
		z-index: 9999;
		background-size: 100% 100%;

		.popup_info_ten {
			width: 100%;
			height: 400rpx;
			margin-top: 120rpx;

			.popup_name {
				width: 100%;
				height: 80rpx;
				background-color: #f8f8f8;
				margin-top: 10rpx;
				line-height: 80rpx;
				text-align: center;

			}
		}

	}

	.login-type-2 {
		width: 100%;
		position: relative;

		.back-btn {
			position: absolute;
			left: 40rpx;
			z-index: 9999;
			top: 40rpx;
			font-size: 48rpx;
		}

		.login-top {
			height: 460rpx;
			position: relative;

			.desc {
				position: absolute;
				top: 200rpx;
				left: 40rpx;
				font-size: 48rpx;

				.title {
					font-size: 48rpx;
				}
			}

			.login-pic {
				position: absolute;
				width: 220rpx;
				height: 270rpx;
				right: 30rpx;
				top: 100rpx;
			}
		}

		.login-type-content {
			position: relative;
			top: -72rpx;

			.login-bg {
				width: 94vw;
				height: 94vw;
				margin: 0 3vw;
			}

			.main {
				width: 94vw;
				position: absolute;
				top: 0;
				left: 3vw;

				.nav-bar {
					display: flex;
					height: 100rpx;
					justify-content: center;
					align-items: center;
					position: relative;
					z-index: 10;

					.nav-bar-item {
						flex: 1;
						display: flex;
						height: 100%;
						line-height: 96rpx;
						display: flex;
						margin: 0 120rpx;
						justify-content: center;
					}

					.nav-bar-item-active {
						border-bottom: 5rpx solid;
					}
				}

				.login-type-form {
					width: 80%;
					margin: 50rpx auto;

					.input-item {
						position: relative;
						height: 90rpx;
						line-height: 90rpx;

						.iconfont {
							font-size: 50rpx;
							position: absolute;
							left: 0;
						}

						.login-type-input {
							height: 90rpx;
							padding-left: 80rpx;
							border-bottom: 1rpx solid rgba(0, 0, 0, .1);
						}

						.sms-code-btn,
						sms-code-resend {
							width: 240rpx;
						}
					}
				}

				.login-type-tips {
					padding: 0 50rpx;
					display: flex;
					justify-content: space-between;
				}


			}
		}

		.login-type-bottom {
			width: 100%;
			padding-bottom: 30rpx;
			text-align: center;
		}
	}
</style>